//@ts-check
import { xml2json } from 'xml-js';
import { reduce } from 'lodash-es';

const parse = (/** @type {string} */ str) => {
  /**@type {import('./xml-js').DocumentStructure} */
  const elements = JSON.parse(xml2json(str));
  const element = elements.elements[0];
  console.log(`${element.name.toLocaleLowerCase()}${reduce(element.attributes, (pre, v, k) => {
    if (k === 'class') {
      return pre + '.' + v.split(' ').join('.');
    }
    return pre + `[${k}="${v}"]`;
  }, '')}`);
};
parse(`<button type="button" class="Button Button--secondary Button--grey css-ebmf5v">取消</button>`);